import re
import requests

s = requests.session()
url_login = 'http://192.168.5.116/TinyShop_v1.7/index.php?con=simple&act=login_act'
data_login = {'email': '126@126.com', 'password': 123456}
s.post(url=url_login, data=data_login)
print('第一处')
r1 = s.post(url='http://192.168.5.116/TinyShop_v1.7/index.php?con=index&act=cart_add',
            data={'id': 27, 'num': 1})  # 加入购物车
print('第二处')
r2 = s.get('http://192.168.5.116/TinyShop_v1.7/index.php?con=simple&act=cart')  # 去结算
print('第三处')
r3 = s.get('http://192.168.5.116/TinyShop_v1.7/index.php?con=simple&act=order')  # 结算
print('第四处')
r4 = s.post('http://192.168.5.116/TinyShop_v1.7/index.php?con=simple&act=get_voucher',
            {'amount': 16699, 'page': 2})  # 结算
print('第5处')
r5 = s.post('http://192.168.5.116/TinyShop_v1.7/index.php?con=ajax&act=calculate_fare', {'weight': 3405, 'id': 2})  # 结算
print('第6处')
r6 = r3.text
va = re.findall(r"type='hidden' name='tiny_token_order' value='(.+?)'/>", r6)
print(va)
print(type(va))
r7 = s.post('http://192.168.5.116/TinyShop_v1.7/index.php?con=simple&act=order_act', {'address_id': 2,
                                                                                      'payment_id': 1,
                                                                                      'user_remark': '%E5%8F%91%E9%A1%BA%E4%B8%B0%E5%BF%AB%E9%80%92',
                                                                                      'invoice_type': 0,
                                                                                      'invoice_title': '',
                                                                                      'tiny_token_order': va})  # 提交订单
print('第7处')
r8 = r7.text

va2 = re.findall('type="hidden" name="order_id" value="(.+?)">', r8)
va2_1 = va2[0]
va3 = re.findall('</td><td><i class="icon-order-0 ie6png"></i>(.+?) &nbsp;&nbsp;', r8)
print(va3)
r9 = s.post('http://192.168.5.116/TinyShop_v1.7/index.php?con=payment&act=dopay',
            {'order_id': va2_1, 'payment_id': 1, 'channelBank': 'ICBC'})
va4 = re.findall("type='hidden' name='sign' value='(.+?)' />", r9.text)
# va4_1=va4[0]
# print(va4_1)
print(va4[0])
r10 = s.post('http://192.168.5.116/TinyShop_v1.7/index.php?con=payment&act=pay_balance',
             {'attach': 1, 'total_fee': 16724.00, 'order_no': va3,
              'return_url': 'http://192.168.5.116/TinyShop_v1.7/index.php?con=payment&act=callback&payment_id=1',
              'sign': va4[0]})
print(r10.text)

#
# class front_shopping:
#     def front_new(self,li,data):
#         s = requests.session()
#         dic_url=eval(li)
#         r1 = s.get(dic_url['url1'])
#         r2 = r1.text
#         qq = re.findall(r"name='tiny_token_reg' value='(.+?)'/>", r2)
#         va = qq[0]
#         s.headers.update = ({'verifyCode': 'aaaa'})
#         datas =eval(data)
#         rd = s.post(url=dic_url['url'], data=datas)
#         # print(rd.text)
#         return rd.text
#     def judge_new(self,li):
#         '''
#         注册专用校验方法
#         :param li: 整行数据
#         :return: 返回校验结果
#         '''
#         res=self.front_new(li[6],data=li[7])
#         st = str(li[8])
#         if st in res:
#             put_write="测试通过"
#         else:
#             put_write="测试不通过"
#         return put_write
